package cn.hesion.singlton;
/**
 * ClassName: PropTool <br/>
 * Description: <br/>
 * date: 2021/1/27 18:22<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import cn.hesion.log.LogCollectorTask;

import java.io.IOException;
import java.util.Properties;

/**
 * @program: ClientDemo
 * @description: 配置类对象
 * @author: hesion
 * @create: 2021-01-27 18:22
 **/
public class PropTool2 {
    // 这个代码虽然实现了单例模式，但仅适用单线程的情况
    private static  volatile  Properties prop = null;
     public static  Properties getProp(){
         if(null == prop){
             synchronized ("lock"){
                 if(null == prop){
                     prop = new Properties();
                     try {
                         prop.load(LogCollectorTask.class.getClassLoader().getResourceAsStream("collector.properties"));
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
                 }
             }
         }
         return prop;
     }
}
